package deployr.cli;

import java.io.*;

public class Command {

	private final Command other;

	public Command(Command other) {
		this.other = other;
	}

	public int run(OutputStream output, String[] args) {
		if (shouldProcess(args))
			return onRun(output, args);

		return forward(output, args);
	}

	protected int onRun(OutputStream output, String[] args) {
		return 0;
	}

	protected void puts(OutputStream output, String string) {
		try {
			output.write(string.getBytes());
			output.write("\n".getBytes());
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	protected int forward(OutputStream output, String[] args) {
		return other.run(output, args);
	}

	protected boolean shouldProcess(String[] args) {
		return true;
	}

	public void usage(OutputStream output) {
		
	}

}